<!DOCTYPE html>
<html>
<head>
    {include file="layout:_meta" /}
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">分类名</label>
        <div class="layui-input-block">
            <input type="text" name="name"  placeholder="请输入分类名" lay-verify="required"  value="{:isset($list.name)?$list.name:''}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!--图片上传-->
    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">缩略图</label>-->
        <!--<div class="layui-input-inline uploadHeadImage">-->
            <!--<div class="layui-upload-drag" id="headImg">-->
                <!--<i class="layui-icon"></i>-->
                <!--<p>点击上传图片，或将图片拖拽到此处</p>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="layui-input-inline">-->
            <!--<div class="layer-photos-demo layui-upload-list"style="text-align: center;margin: 0px !important;"  id="layer-photos-demo">-->

                <!--<img  src="{:isset($list.thumb)?$list.thumb:''}" lass="layui-upload-img headImage" height="155px" onclick="showBigImage(this)" id="demo1" >-->
                <!--<input type="hidden" id="ad_img" name="thumb" value="{:isset($list.thumb)?$list.thumb:''}">-->
                <!--<p id="demoText">缩略图  不大于 120kb </p>-->
            <!--</div>-->
        <!--</div>-->
    <!--</div>-->
    <!--图片上传 end-->
    <div class="layui-form-item">
        <label class="layui-form-label">序号</label>
        <div class="layui-input-block">
            <input type="number" name="sort" lay-verify="" placeholder="请输入序号 数字越小排序越靠前" lay-reqtext=""  autocomplete="off" value="{:isset($list.sort)?$list.sort:''}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类描述</label>
        <div class="layui-input-block">
            <textarea name="description" lay-verify="" placeholder="请输入描述" autocomplete="off" class="layui-textarea">{:isset($list.description)?$list.description:''}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            {if condition="isset($list.state)&&$list.state==1"}
            <input type="checkbox" lay-filter="state"  checked value="1" name="state" lay-skin="switch" lay-text="启用|禁用">
            {else /}
            <input type="checkbox" lay-filter="state"  value="0" name="state" lay-skin="switch" lay-text="启用|禁用">
            {/if}
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
        <input type="hidden" name="token" value="{:isset($list['token'])?$list['token']:''}">
        <input type="button" lay-submit lay-filter="addEdit" id="addEdit" value="确认">
    </div>
</div>
{include file="layout:_footer" /}
<script>
    layui.config({
        base: '__static__/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','upload'], function(){
        var form = layui.form,$ = layui.$,upload = layui.upload;



        // form.verify({
        //     username: function (value, item) { //value：表单的值、item：表单的DOM对象
        //         var msg;
        //         $.ajax({
        //             async: false,
        //             url: "{:url('goods_cate/check')}",
        //             data: {username: value},
        //             success: function (data) {
        //                 if (data.code) {
        //                     msg = data.msg;
        //                 }
        //             }
        //         });
        //         return msg;
        //     },
        //
        // });

        //拖拽上传
        var uploadInst = upload.render({
            elem: '#headImg'
            , url: "/admin/index/upload_img"+'?uptype=goods_cate'
            , size: 120
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                console.log(res.code,'==========================>图片上传返回<');
                //如果上传失败
                if (res.code != 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
                /*   console.log(res.data.src);*/
                //   window.parent.uploadHeadImage(res.files);
                var demoText = $('#demoText');
                // $('#ad_img').val(res.files);
                $('#ad_img').val(res.data.img_url);
                console.log(demoText,'===========>,<!!!');
                demoText.html('<span style="color: #8f8f8f;">上传成功!!!</span>');
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        form.on('switch(state)', function(data){
            this.value = this.checked?1:0;
        });
    })
</script>
</body>
</html>